#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# Port configuration - different from existing iceberg rest ports
# Existing iceberg uses 18181, we use 19181-19183 to avoid conflicts
export ICEBERG_REST_S3_PORT=19181
export ICEBERG_REST_OSS_PORT=19182
export ICEBERG_REST_COS_PORT=19183
export ICEBERG_REST_OBS_PORT=19184
export ICEBERG_REST_GCS_PORT=19185
export ICEBERG_REST_HDFS_PORT=19186

# Built-in HDFS Configuration - using special ports to avoid conflicts
# NameNode WebUI: 20870 (instead of 9870)
# NameNode RPC: 20020 (instead of 8020)
# DataNode WebUI: 20864 (instead of 9864)
export HDFS_NAMENODE_WEBUI_PORT=20870
export HDFS_NAMENODE_RPC_PORT=20020
export HDFS_DATANODE_WEBUI_PORT=20864

# Auto-detect local machine IP for HDFS access
# This ensures both Doris FE and iceberg-rest can access HDFS using the same IP
if command -v ip >/dev/null 2>&1; then
    # Linux: get default route interface IP
    export LOCAL_IP=$(ip route get 1.1.1.1 | grep -oP 'src \K\S+' 2>/dev/null || echo "127.0.0.1")
elif command -v ifconfig >/dev/null 2>&1; then
    # macOS: get en0 interface IP
    export LOCAL_IP=$(ifconfig en0 | grep 'inet ' | awk '{print $2}' 2>/dev/null || echo "127.0.0.1")
else
    # Fallback to localhost
    export LOCAL_IP="127.0.0.1"
fi

echo "Detected local IP for HDFS: $LOCAL_IP"

# AWS S3 Configuration
export AWSAk="*****************"
export AWSSk="*****************"
export AWSEndpoint="s3.ap-east-1.amazonaws.com"
export AWSRegion="ap-east-1"

# Alibaba Cloud OSS Configuration  
export OSSAk="*****************"
export OSSSk="*****************"
export OSSEndpoint="oss-cn-beijing.aliyuncs.com"
export OSSRegion="cn-beijing"

# Tencent Cloud COS Configuration
export COSAk="*****************"
export COSSk="*****************"
export COSEndpoint="cos.ap-beijing.myqcloud.com"
export COSRegion="ap-beijing"

# HUAWEI Cloud OBS Configuration
export OBSAk="*****************"
export OBSSk="*****************"
export OBSEndpoint="obs.cn-north-4.myhuaweicloud.com"
export OBSRegion="cn-north-4"

# Google Cloud Storage Configuration
export GCSAk='*****************'
export GCSSk='*****************'
export GCSEndpoint='storage.googleapis.com'
export GCSRegion='asia-east2'
